﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using BusinessObjects.BO_GetObjects;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{

    public WebService()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public bool LogoBannerDelete(string id)
    {
        try
        {
            string path = Server.MapPath("../upload/xml/logo-banner.xml");
            DataSet objDS = new DataSet();
            objDS.ReadXml(path);
            DataTable tb = objDS.Tables[0];
            string[] ids = id.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            int max = 1000;
            for (int i = 0; i < ids.Length; i++)
            {
                int val = -1;
                for (int j = 0; j < ids.Length; j++)
                {
                    int cur = Convert.ToInt32(ids[j]);
                    if (cur > val && cur < max)
                        val = cur;
                }
                max = val;
                tb.Rows.RemoveAt(val);
            }
            objDS.WriteXml(path);
            return true;
        }
        catch { return false; }
    }
    [WebMethod]
    public bool LogoBannerOrder(string id)
    {
        try
        {
            string path = "../upload/xml/logo-banner.xml";
            DataSet objDS = new DataSet();
            objDS.ReadXml(Server.MapPath(path));
            DataTable tb = objDS.Tables[0];
            DataTable objDT = new DataTable("banner");
            objDT.Columns.Add("THUMB_IMG");
            objDT.Columns.Add("LINK");
            string str = String.Empty;
            string[] ids = id.Split(new string[] { "&table-3[]=" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < ids.Length; i++)
            {
                DataRow drow = objDT.NewRow();
                drow["THUMB_IMG"] = tb.Rows[Convert.ToInt32(ids[i]) - 1]["THUMB_IMG"];
                drow["LINK"] = tb.Rows[Convert.ToInt32(ids[i]) - 1]["LINK"];
                objDT.Rows.Add(drow);
            }
            objDS.Tables.Remove(tb);
            objDS.Tables.Add(objDT);
            objDS.WriteXml(Server.MapPath(path));
            return true;
        }
        catch { return false; }
    }
    [WebMethod]
    public bool adsorder(string id, int mid)
    {
        try { return BO_Ads_Picture.Order(id, ";", 1); ;        }
        catch { return false; }
    }
    [WebMethod]
    public bool productorder(string id, int mid)
    {
        try { return BO_Products.Order(mid, id); }
        catch { return false; }
    }
    [WebMethod]
    public bool orderthreads(string id, int mid)
    {
        try { return BO_Threads.Order(mid, id); }
        catch { return false; }
    }
}
